<?php
// 新闻
class NewsAction extends Action {
    
	public function index(){
		
		$name = $this->getActionName();
		$m = M($name);
		$map=array('status'=>1);
		$list = $m->where($map)->order('create_time desc')->limit(10)->select();

		$this->assign('list',$list);
		$this->display();
    }

	//显示详细新闻
	public function detail()
	{
		$id = $this->_get('id');
		$m = M('News');
		$new = $m->find($id);
		$this->assign('new',$new);
		$this->display();
	}
	public function getnews()
	{
		$m = M('News');
		import('ORG.Util.Page');// 导入分页类
		$map=array('status'=>1);
		$count      = $m->where($map)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,10);// 实例化分页类 传入总记录数
		$Page->rollPage = 20;	//最多显示20个分页
		// 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
		$nowPage = isset($_GET['p'])?$_GET['p']:1;
		$list = $m->where($map)->order('create_time desc')->page($nowPage.','.$Page->listRows)->select();
		$Page->setConfig('theme','%upPage% %downPage% %prePage% %linkPage% %nextPage%');
		$show       = $Page->show();// 分页显示输出

		$this->ajaxReturn(array('list'=>$list,'page'=>$show));

	}
	
	public function getnewsbyid()
	{
		$id = $this->_get('id');
		$m = M('News');
		$new = $m->find($id);	
		$this->ajaxReturn(array('new'=>$new));
	}
	

}

